package com.omybug;


import com.omybug.study.config.BeanConfig;
import com.omybug.study.entity.People;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringApplication {

    public static void main(String[] args) {
        startWithAnnotation();
    }


    public static void startWithAnnotation(){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BeanConfig.class);
        People people = (People) applicationContext.getBean("people");
        System.out.println(people);
        String[] names = applicationContext.getBeanNamesForType(People.class);
        for (String name : names) {
            System.out.println(name);
        }
    }


    public static void startWithXml(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
        People people = (People)applicationContext.getBean("people");
        System.out.println(people.toString());
    }

}
